package com.example.dynamicproxy2;

import java.lang.reflect.Proxy;

/**
 * @version 1.0.0
 * @className: Test
 * @description:
 * @author: zhangjunfa
 * @date: 2022/6/22 15:50
 */
public class Test {
    public static void main(String[] args) {
        System.out.println("~~~~~~~~~~~~~~~~~~~方法一~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        //1
        CatProxy catProxy = new CatProxy();
        CatInterface proxy = (CatInterface) catProxy.getProxy();
        proxy.run();
        proxy.eat();
        proxy.stop();

        System.out.println("-----------方法二-----------------");
        //2
        CatInterface cat = new Cat();
        CatInterface catInterface = (CatInterface) Proxy.newProxyInstance(cat.getClass().getClassLoader(), cat.getClass().getInterfaces(), new CatSystemProxy(cat));
        catInterface.run();
        catInterface.eat();
        catInterface.stop();

        System.out.println("=============方法三===================");
        //3
        CatInterface catInterface1 = new Cat();
        CatSystemProxy catSystemProxy = new CatSystemProxy(catInterface1);
        CatInterface res= (CatInterface) catSystemProxy.getProxy();
        res.run();
        res.eat();
        res.stop();
    }
}
